import { Application } from 'egg';
import { Instance } from 'sequelize';

type status = 'success' | 'error' | 'waiting';

export interface PagesAttributes {
  status: status;
  url: string;
  error_message: string;
}

export interface PagesInstance extends Instance < PagesAttributes >, PagesAttributes {
  id?: number;
  createdAt: Date;
  updatedAt: Date;
}

export default (app: Application) => {

  const { STRING, TEXT, ENUM } = app.Sequelize;

  const Pages = app.model.define< PagesInstance, PagesAttributes >('pages', {
    url: STRING(255),
    error_message: TEXT,
    status: ENUM(['success', 'error', 'waiting']),
  });

  Pages.associate = () => {
    Pages.hasMany(app.model.Lists);
  };

  return Pages;
};